package cn.kgc.spring02.entity.factory;

import org.springframework.beans.factory.FactoryBean;

import java.sql.Connection;
import java.sql.DriverManager;

/**
 * @Author: 课工场
 * @Version: v1.0  2023/4/27
 * @Description:  获取数据库连接的工厂
 */
public class ConnectionFactory implements FactoryBean<Connection> {


    public Connection getObject() throws Exception {
        Class.forName("com.mysql.jdbc.Driver");
        String url = "jdbc:mysql:///java2218";
        String username="root";
        String password = "root";
        Connection connection = DriverManager.getConnection(url, username, password);
        return connection;
    }

    public Class<?> getObjectType() {
        return Connection.class;
    }
}
